rust empty vector

507

create empty vector in rust -

///Creates and returns empty vector
vec![]

///Creates and returns vector of length 'l' with default value 'v'
vec![v; l] /// vec![0; 3] returns [0,0,0]

///Creates and returns vector of length 'l' with default value 'v' of datatype 'T'
vec![vT; l]; /// vec![3u8; 2] returns [3, 3] 

///Creates empty vector with specific type 'T' and capacity 'c'
Vec::<T>::with_capacity(c)

rust empty vector -

let mut vec = Vec::new();

get length of vector rust -

let a = vec![1, 2, 3];
assert_eq!(a.len(), 3);

Comments

Submit
0 Comments